<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2019/2/23
 * Time: 8:35
 */
namespace App\Services\Campaign\Platform;

use App\Model\Expertes;
use App\Services\CommonService;

class ExpertService extends CommonService{

    //查询 二十条
    public function SelAll(){
       $data=Expertes::offset(0)->limit(20)->get();
       if($data){
           return $data;
       }
       else{
           return array();
       }
    }


    //查询一条
    public function SellOne($request){
        //查询一条数据  主键id=￥id的
        $data=Expertes::find($request['id'])->toArray();
//        return $data;
        if($data){
            //查询猜你喜欢
            $experts_type=$data['experts_type'];
            //专家类型不存在
            if(!isset($experts_type)){
                return $res['code']=105;
             }

            $arr=$this->SelType($experts_type);
             //查询类型失败
            if($arr==array()){
                return $res['code']=100;
            }
            else{
                $data['data']=$data;
                $data['arr']=$arr;
               $res['code']=200;
               $res['data']=$data;
              return $res;
            }

        }else{
            return $res['code']=100;
        }
    }

    //查找专家类型  限制3条
    public function SelType($experts_type){
        $data=Expertes::where('experts_type','=',$experts_type)->inRandomOrder()->take(4)->get()->toArray();
        if($data){
            return $data;
        }
        else{
            return array();
        }
    }




    /**
     * 添加专家信息
     */
    public function ExpertsAdd($request){
        $use=new Expertes();
        $use->expertes_name=$request['expertes_name'];
        $use->expertes_buscard=$request['expertes_buscard'];
        $use->experts_title=$request['experts_title'];
        $use->experts_dgst=$request['experts_dgst'];
//        $use->experts_img=
    }

    /**
     * 上传图片
     */
    public function UploadImgs($request){
        $data=$this->UploadImg($request);
        return $data;
    }
}